package com.example.asapp.demo.curd;

import com.example.asapp.afbz.FbzApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.UUID;

import org.springframework.web.bind.annotation.GetMapping;

@RestController
@Slf4j
@RequestMapping(FbzApi.api+"/demo/curd")
public class CurdController extends FbzApi{

    @Autowired
    CurdService curdService;

    @GetMapping("list")
    public List<CurdVO> getCities(){
        return curdService.findAll();
    }

    @PostMapping
    public CurdVO add(@RequestBody CurdVO curdVO){
        curdVO.setId(UUID.randomUUID().toString());
        return curdService.add(curdVO);
    }

    @PutMapping
    public CurdVO update(@RequestBody CurdVO curdVO){
        return curdService.update(curdVO);
    }

    @DeleteMapping("{id}")
    public void delete(@PathVariable String id){
        curdService.deleteById(id);
    }


    @GetMapping("query")
    public List<CurdVO> query(){
        return curdService.listAll();
    }
}
